/**
 * Automatic Subtitle Downloader
 * http://code.google.com/p/autosubdown/
 * 
 * Copyright 2010-2011 Raphael Medeiros.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */
package com.byraphaelmedeiros.autosubdown;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.byraphaelmedeiros.autosubdown.domain.Config;

/**
 * @author Raphael Medeiros
 *
 */
public class AutoSubDownThread implements Runnable {
	
	private static Logger LOGGER = Logger.getLogger(AutoSubDownThread.class.getName());

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		try {
			Config config = Config.getInstance();
			
			config.load();
			
			long sleep = config.getWait();
			
			LOGGER.log(Level.INFO, "Starting DAEMON mode with checks every " + sleep + " milliseconds...");
			
			while (true) {
				AutoSubDown.download();
				
				Thread.sleep(sleep);
			}
		} catch (InterruptedException e) {
			//e.printStackTrace();
			LOGGER.log(Level.INFO, "DAEMON mode stopped!");
		}
	}
}